package com.sunny.example.list;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class HJ48_从单向链表中删除指定值 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int total = scanner.nextInt();
            int head = scanner.nextInt();
            List<Integer> list = new ArrayList<>();
            list.add(head);

            for (int i = 0; i < total - 1; i++) {
                int value = scanner.nextInt();
                int node = scanner.nextInt();
                list.add(list.indexOf(node) + 1, value);
            }

            int deleteValue = scanner.nextInt();
            list.remove(list.indexOf(deleteValue));

            for (int i = 0; i < list.size(); i++) {
                System.out.print(list.get(i) + " ");
            }
        }
    }
}
